package com.zrf.geekbang.spring.bean;

import com.zrf.geekbang.spring.ioc.overview.domain.User;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.GenericBeanDefinition;

/**
 * {@link org.springframework.beans.factory.config.BeanDefinition}
 * @author zhouruifeng
 * @date 2020-06-21
 */
public class BeanDefinitionCreateDemo {
    public static void main(String[] args) {
        //通过beanDefinition Builder
        BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(User.class);
        //通过属性设置操作
        beanDefinitionBuilder.addPropertyValue("id", 1111);
        beanDefinitionBuilder.addPropertyValue("name", BeanDefinitionCreateDemo.class.toString());
        //获取beanDefinition实例
        BeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition();
        //beanDefinition并非是bean的终态,可以自定义修改

        //通过abstractBeanDefinition及其派生
        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        //设置bean类型
        genericBeanDefinition.setBeanClass(User.class);
        MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
        mutablePropertyValues.addPropertyValue("id", 1111);
        mutablePropertyValues.addPropertyValue("name", BeanDefinitionCreateDemo.class.toString());
        genericBeanDefinition.setPropertyValues(mutablePropertyValues);
        User user = null;
    }
}
